﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml;

namespace PefStudio.SegyViewer
{
    class TraceSets
    {
        public event EventHandler TraceHeaderExtractStyleChanged;
        private string _traceHeaderExtractStyle = "中文标准";

        [TypeConverter(typeof(TraceHeaderExtractStyle))]
        [CategoryAttribute("解析方式"), DisplayName("道头解析"), DescriptionAttribute("道头解析方式")]
        public string TraceHeaderExtractStyle
        {
            set 
            {
                if (value != _traceHeaderExtractStyle)
                {
                    _traceHeaderExtractStyle = value;

                    if(TraceHeaderExtractStyleChanged != null)
                        TraceHeaderExtractStyleChanged(this, new EventArgs());
                }
            }
            get { return _traceHeaderExtractStyle; }
        }

        [CategoryAttribute("字段设置"), DisplayName("道头字段集合"), DescriptionAttribute("道头字段集合")]
        public List<HeaderField> TraceHeaderFields
        {
            get
            {
                return SegyViewerSetting.TraceHeaderFieldSets[_traceHeaderExtractStyle];
            }
        }

        public event EventHandler ReelHeaderExtractStyleChanged;
        private string _reelHeaderExtractStyle = "English";

        [TypeConverter(typeof(ReelHeaderExtractStyle))]
        [CategoryAttribute("解析方式"), DisplayName("卷头解析"), DescriptionAttribute("卷头解析方式")]
        public string ReelHeaderExtractStyle
        {
            set
            {
                if (value != _reelHeaderExtractStyle)
                {
                    _reelHeaderExtractStyle = value;

                    if (ReelHeaderExtractStyleChanged != null)
                        ReelHeaderExtractStyleChanged(this, new EventArgs());
                }
            }
            get { return _reelHeaderExtractStyle; }
        }

        [CategoryAttribute("字段设置"), DisplayName("卷头字段集合"), DescriptionAttribute("卷头字段集合")]
        public List<HeaderField> ReelHeaderFields
        {
            get
            {
                return SegyViewerSetting.ReelHeaderFieldSets[_reelHeaderExtractStyle];
            }
        }

        public event EventHandler TracesPerPageChanged;
        private int _tracesPerPage = 100;

        [CategoryAttribute("图形设置"), DisplayName("每页道数"), DescriptionAttribute("每页道数")]
        public int TracesPerPage
        {
            set
            {
                if (value != _tracesPerPage)
                {
                    _tracesPerPage = value;

                    if (TracesPerPageChanged != null)
                        TracesPerPageChanged(this, new EventArgs());
                }
            }
            get { return _tracesPerPage; }
        }

        public event EventHandler SamplePointsPerPageChanged;
        private int _samplePointsPerPage = 500;

        [CategoryAttribute("图形设置"), DisplayName("每页采样点数"), DescriptionAttribute("每页采样点数")]
        public int SamplePointsPerPage
        {
            set
            {
                if (value != _samplePointsPerPage)
                {
                    _samplePointsPerPage = value;

                    if (SamplePointsPerPageChanged != null)
                        SamplePointsPerPageChanged(this, new EventArgs());
                }
            }
            get { return _samplePointsPerPage; }
        }

        //public event EventHandler SamplePointsPerPageChanged;
        //private int _SamplePointsPerPage = 1;

        //[CategoryAttribute("图形设置"), DisplayName("每页采样点数"), DescriptionAttribute("每页采样点数")]
        //public int SamplePointsPerPage
        //{
        //    set
        //    {
        //        if (value != _SamplePointsPerPage)
        //        {
        //            _SamplePointsPerPage = value;

        //            if (SamplePointsPerPageChanged != null)
        //                SamplePointsPerPageChanged(this, new EventArgs());
        //        }
        //    }
        //    get { return _SamplePointsPerPage; }
        //}
    }

    public class HeaderField
    {
        [DisplayName("名称"), DescriptionAttribute("名称")]
        public string Name
        {
            get;
            set;
        }

        [DisplayName("字节数"), DescriptionAttribute("字节数")]
        public int Size
        {
            get;
            set;
        }

        [DisplayName("说明"), DescriptionAttribute("说明")]
        public string Description
        {
            get;
            set;
        }

        [DisplayName("取样点字段"), DescriptionAttribute("取样点字段")]
        public bool IsSamplePoint
        {
            get;
            set;
        }

        public HeaderField()
        {
        }

        public HeaderField(string name)
        {
            Name = name;
        }

        public HeaderField(string name, int size)
            : this(name)
        {
            Size = size;
        }
    }

    public class TraceHeaderExtractStyle : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return Values;
        }

        private StandardValuesCollection _values;

        private StandardValuesCollection Values
        {
            get
            {
                if (_values == null)
                {
                    _values = new TypeConverter.StandardValuesCollection(SegyViewerSetting.TraceHeaderFieldSets.Keys);
                }
                return _values;
            }
        }
    }

    public class ReelHeaderExtractStyle : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return Values;
        }

        private StandardValuesCollection _values;

        private StandardValuesCollection Values
        {
            get
            {
                if (_values == null)
                {
                    _values = new TypeConverter.StandardValuesCollection(SegyViewerSetting.ReelHeaderFieldSets.Keys);
                }
                return _values;
            }
        }
    }
}
